/**
 * @Copyright ®2015 Sinosoft Co. Ltd. All rights reserved.
 * 项目名称 : 统一支付平台
 * 创建日期 : 2017-09-13
 * 修改历史 :
 * 1. [2017-09-13]创建文件 by chenxin
 */
package com.gavinwind.uic.customer.web.restapi;

import com.gavinwind.uic.customer.biz.service.CustomerMngService;
import com.gavinwind.uic.customer.common.model.Customer;
import com.gavinwind.uic.customer.dto.CustomerRegParam;
import com.gavinwind.uic.customer.dto.CustomerSaveParam;
import com.gavinwind.uic.customer.facade.CustomerOperateFacadeService;
import com.sinosoft.platform.common.base.SinoBaseService;
import com.sinosoft.platform.common.exception.biz.BizRuleException;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * 【客户操作Facade服务接口实现类】
 * @author chenxin
 * @date 2017-09-13 下午2:42 
 * @version V1.0
 */
@RestController
@RefreshScope
@RequestMapping(value="/uic/customerOper")
public class CustomerOperateRestController extends SinoBaseService implements CustomerOperateFacadeService {
    @Autowired
    private CustomerMngService customerMngService;
    /**
     * 注册新客户(快捷方法)
     * @param regCustomer
     * @return
     * @throws BizRuleException
     */

    @ApiOperation(value="注册新用户", notes="通过客户简要信息注册新用户,如果发现用户名已经存在则抛出异常")
    @ApiImplicitParam(name = "regCustomer", value = "注册用户实体", required = true, dataType = "CustomerRegParam")
    @RequestMapping(value="register", method= RequestMethod.POST)
    public String registerNewCustomer(@RequestBody CustomerRegParam regCustomer) throws BizRuleException {
        return null;
    }

    /**
     * 保存客户信息 (可以新增可以更新)
     * @param customer  客户编码
     * @throws BizRuleException
     */
    @ApiOperation(value="保存客户信息", notes="根据传入的参数信息,保存客户信息,如果是已有客户,则更新客户信息,否则新增客户。客户唯一性校验标准1️⃣五项基本信息为主")
    @ApiImplicitParam(name = "customer", value = "注册用户实体", required = true, dataType = "CustomerSaveParam")
    @RequestMapping(value="saveCustomer", method= RequestMethod.POST)
    public void saveCustomer(@RequestBody CustomerSaveParam customer) throws BizRuleException {
        Customer tCustomer =  customer.trans2CustomerModel();
        customerMngService.saveCustomerInfo(tCustomer);
    }
}
